#include "MsgQueueUtil.h"



//创建mqId
int get_MsgQueue()
{
    //获取key
    key_t key = ftok(PATHNAME_BOA_MAIN,PROCESS_ID_BOA_MAIN);
    if (key == -1)
    {
        perror("fotk(): ");
        return -1;
    }
    //创建或者获取队列返回消息队列id
    int mqId = msgget(key,IPC_CREAT|0666);
    if (mqId == -1)
    {
        perror("msgget(): ");
        return -1;
    }
    return mqId;
}

//发消息
int sendMsg(int mqId,Message* msg,int msgSize)
{
    int ret = msgsnd(mqId,msg,msgSize,0);  //0表示阻塞等待
     if (ret == -1)
    {
        perror("send msg error: ");
        return -1;
    }
    return ret;
}

// 收消息
int recvMsg(int mqId,Message* msg,int msgSize)
{
 int ret = msgrcv(mqId,msg,msgSize,0,0);  //0,第一个类型，0表示阻塞等待
     if (ret == -1)
    {
        perror("recive msg error: ");
        return -1;
    }
}